﻿
using System.Windows.Media;
using Moria.Silverlight.Enum;
using Redbrick.Silverlight.Extentions;

namespace Moria.Silverlight.Model
{
    public class CaveFloor : Drawable
    {
        #region Declarations

        //private Monster _CreaturePtr = null;
        //private InventoryItem _ItemPtr = null;
        private FloorType _FloorType = FloorType.NullWall;
        private bool _IsRoom = false;
        private bool _FieldMark = false;
        private bool _PermLight = false;
        private bool _TempLight = false;

        #endregion

        #region Constructor

        public CaveFloor(DungeonLevel owner)
        {
            if (this.Cave == null) this.Cave = owner;
        }

        #endregion Constructor

        #region Properties


        public DungeonLevel Cave { get; private set; }

        /// <summary>
        /// was cptr
        /// </summary>
        public Monster CreaturePtr
        {
            get { return this.Cave.MonsterAt(this.Y, this.X); }
        }

        /// <summary>
        /// was tptr
        /// </summary>
        public InventoryItem ItemPtr
        {
            get { return this.Cave.ItemAt(this.Y, this.X); }
        }

        /// <summary>
        /// was fval
        /// </summary>
        public FloorType FloorType
        {
            get { return this._FloorType; }
            set
            {
                if (value == this._FloorType) return;
                this._FloorType = value;
                this.RaisePropertyChanged(() => this.FloorType);
            }
        }

        /// <summary>
        /// was lr
        /// </summary>
        public bool IsRoom
        {
            get { return this._IsRoom; }
            set
            {
                if (value == this._IsRoom) return;
                this._IsRoom = value;
                this.RaisePropertyChanged(() => this.IsRoom);
            }
        }

        /// <summary>
        /// was fm
        /// </summary>
        public bool FieldMark
        {
            get { return this._FieldMark; }
            set
            {
                if (value == this._FieldMark) return;
                this._FieldMark = value;
                this.RaisePropertyChanged(() => this.FieldMark);
            }
        }

        /// <summary>
        /// was pl
        /// </summary>
        public bool PermLight
        {
            get { return this._PermLight; }
            set
            {
                if (value == this._PermLight) return;
                this._PermLight = value;
                this.RaisePropertyChanged(() => this.PermLight);
            }
        }

        /// <summary>
        /// was tl
        /// </summary>
        public bool TempLight
        {
            get { return this._TempLight; }
            set
            {
                if (value == this._TempLight) return;
                this._TempLight = value;
                this.RaisePropertyChanged(() => this.TempLight);
            }
        }

        public bool HasItem { get { return this.ItemPtr != null; } }
        public bool HasCreature { get { return this.CreaturePtr != null; } }
        public bool HasLight { get { return this.HasPermLight | this.HasTempLight; } }
        public bool HasTempLight { get { return this.TempLight; } }
        public bool HasPermLight { get { return this.PermLight; } }

        #endregion Properties

        #region Methods

        public override string GetDescription()
        {
            if (this.HasCreature) return this.CreaturePtr.GetDescription();
            if (this.HasItem) return this.ItemPtr.GetDescription();
            if (this.FloorType > FloorType.NullWall && this.FloorType <= FloorType.BoundaryWall)
                return this.FloorType.Description();
            return base.GetDescription();
        }

        public override Glyph GetGlyph()
        {


            if (this._glyph == null)
                this._glyph = new Glyph();
            this._glyph.SymbolColor = Colors.Black;
            //		if (!this.HasPermLight && !this.HasTempLight && !this.FieldMark) this._glyph.Symbol = ' ';	// space
            if (this.HasCreature) return this.CreaturePtr.GetGlyph();
            else if (this.HasItem) return this.ItemPtr.GetGlyph();
            else if (this.FloorType <= FloorType.MaxCaveFloor) this._glyph.Symbol = '•';
            else if (this.FloorType == FloorType.GraniteWall || this.FloorType == FloorType.BoundaryWall) this._glyph.Symbol = '█';
            else this._glyph.Symbol = '░';

            return this._glyph;
        }

        #endregion Methods
    }
}
